home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / FlyThrough 1.1.2 / src / Source / QD3D General Tools / CBoxMaker.cp < prev    next >
Encoding:
Text File  |  1997-03-12  |  1.4 KB  |  59 lines  |  [TEXT/CWIE]

  1. //
  2. //    CBoxMaker.cp
  3. //
  4. //    class CBoxMaker
  5. //    Constructs a single box and assigns colors to each face.
  6. //    Note: The face attributes are members and will be released
  7. //    in the destructor.
  8. //
  9. //    by James Jennings
  10. //    November 23, 1995
  11. //
  12. //    November 26, 1995: Based on CObjectMaker
  13. //
  14.  
  15. #include "CBoxMaker.h"
  16.  
  17. //    Note: I've put all of the initialization that allocates into Make()
  18. //    rather than in the constructor. I'm not sure it matters.
  19.  
  20. CBoxMaker::CBoxMaker( float inSize )
  21. {    // init box data
  22.     ::Q3Point3D_Set(&mData.origin, 0.0, 0.0, 0.0);
  23.     ::Q3Vector3D_Set(&mData.orientation, 0.0, inSize, 0.0);
  24.     ::Q3Vector3D_Set(&mData.majorAxis, 0.0, 0.0, inSize);    
  25.     ::Q3Vector3D_Set(&mData.minorAxis, inSize, 0.0, 0.0);    
  26.     mData.boxAttributeSet = nil;
  27.     
  28.     // set up the face attributes pointer
  29.     for (int f=0; f<numFaces; f++)
  30.         mFaces[f] = 0;
  31.     mData.faceAttributeSet = mFaces;
  32. }
  33.  
  34. CBoxMaker::~CBoxMaker()
  35. {
  36.     for (int f=0; f<numFaces; f++)
  37.         if (mFaces[f]) {
  38.             ::Q3Object_Dispose(mFaces[f]);
  39.             mFaces[f] = 0;
  40.         }
  41. }
  42.  
  43. void
  44. CBoxMaker::Make()
  45. {
  46.     TQ3ColorRGB color;
  47.     
  48.     // init the face attributes
  49.     for (int f = 0; f<numFaces; f++) {
  50.         mFaces[f] = ::Q3AttributeSet_New();
  51.         ThrowIfNil_(mFaces[f]);
  52.         ::Q3ColorRGB_Set( &color, (((f+1)&1)?1.0:0.0), (((f+1)&2)?1.0:0.0), (((f+1)&4)?1.0:0.0) );
  53.         ::Q3AttributeSet_Add(mFaces[f], kQ3AttributeTypeDiffuseColor, &color);
  54.     }
  55.     // create the box
  56.     mObject = ::Q3Box_New(&mData);
  57.     ThrowIfNil_(mObject);
  58. }
  59.